package acom.test.swing.bb;

import java.awt.FlowLayout;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.util.Observable;

import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JPanel;

public class ButtonPanel extends Observable{
	
	private JPanel thisPanel = new JPanel();
	
	private JButton run_but;  
	private JButton stop_but;
	private JButton showResult_but;  //显示结果
	
	private int butNum ;
	private static final int RUN=1;
	private static final int STOP=2;
	private static final int SHOW=3;
	
	public ButtonPanel(){
		
		//thisPanel.setLayout(new FlowLayout(FlowLayout.CENTER));
		thisPanel.setLayout(null);
		
		ImageIcon run_icon = SystemUtil.createImageIcon("run_but.jpg");
		ImageIcon stop_icon = SystemUtil.createImageIcon("stop_but.png");
		ImageIcon show_icon = SystemUtil.createImageIcon("show_but.png");
		
		run_but = new JButton(run_icon);
		stop_but = new JButton(stop_icon);
		showResult_but = new JButton(show_icon);
		
		init();
				
		thisPanel.add(run_but);
		thisPanel.add(stop_but);
		thisPanel.add(showResult_but);
		
		
	}
	
	private void init(){
		
		run_but.setBounds(100,10,136, 41);
		stop_but.setBounds(280,10,136, 41);
		showResult_but.setBounds(450,10,136, 40);
		
		run_but.addMouseListener(new MouseAdapter(){
			public void mouseClicked(MouseEvent e) {
				notifyTheObservers(RUN);
			}
		});
		stop_but.addMouseListener(new MouseAdapter(){
			public void mouseClicked(MouseEvent e) {
				notifyTheObservers(STOP);
			}
		});
		showResult_but.addMouseListener(new MouseAdapter(){
			public void mouseClicked(MouseEvent e) {
				notifyTheObservers(SHOW);
			}
		});
	}
	
	public JPanel getPane(){
		return thisPanel;
	}
	
	private void notifyTheObservers(int flag){		
		setButNum(flag);
		this.setChanged();
	    this.notifyObservers();
	}

	public int getButNum() {
		return butNum;
	}

	public void setButNum(int butNum) {
		this.butNum = butNum;
	}
		
}
